package org.xlh.springboot.config;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

@Component
//将配置文件中的属性值一次性的绑定倒bean对象的属性上
@ConfigurationProperties(prefix = "myapp")
public class AppConfig {
    //强调：要实现这种一次性的绑定功能，这里的属性名要和配置文件中的key值保持一致
    private String username;
    private String password;
    private Integer age;
    private Boolean gender;

    //底层在实现给对象属性赋值时，用的是反射，调用了setter方法，所以必须保证每个属性提供了setter方法

    public void setGender(Boolean gender) {
        this.gender = gender;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    @Override
    public String toString() {
        return "AppConfig{" +
                "username='" + username + '\'' +
                ", password='" + password + '\'' +
                ", age=" + age +
                ", gender=" + gender +
                '}';
    }
}
